<template>
  <div>
    <el-dialog
      :title="title"
      :visible="dialogVisible"
      :show-close="false"
      width="1000px"
    >
      <manage-info :row="row" />
      <depature-info :row="row" />
      <break-down-info :row="row" />
      <with-drawal-info :row="row" />
      <div>
        <el-form
          ref="refundManageDialog"
          :model="form"
          label-width="130px"
        >
          <el-row
            type="flex"
            justify="space-between"
            style="margin-top: 25px"
          >
            <el-col class="refund-manag-title">押金明细</el-col>
          </el-row>
          <el-row style="margin-top: 15px">
            <el-col :span="8">
              <el-form-item label="总收取押金:" prop="deposit">
                <div>{{ row.deposit ? row.deposit : '-' }}</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="收车问题扣取押金:" prop="withdrawal">
                <div>{{ row.withdrawal ? row.withdrawal : '-' }}</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="违章扣取押金:" prop="violation">
                <el-input
                  v-model="row.violation"
                  size="medium"
                  placeholder="请输入违章扣取押金"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="需退押金总额:" prop="refund">
                <div>{{ row.refund ? row.refund : '-' }}</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="违章凭证:" prop="break">
                <upload-car-state
                  :folder="breakFolder"
                  :row="row"
                  :img="row.break"
                  @upload-success="handleUploadBreak"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="备注:" prop="breakDes">
                <el-input
                  v-model="row.breakDes"
                  size="medium"
                  placeholder="请输入备注"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="GPS分析:" prop="gps">
                <el-input
                  v-model="row.gps"
                  size="medium"
                  placeholder="请输入GPS分析"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <span slot="footer">
        <el-button
          @click="handleCancel"
        >
          取 消
        </el-button>
        <el-button
          type="primary"
          @click="handleConfirm"
        >
          确 定
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import ManageInfo from '@/components/ManageInfo'
import DepatureInfo from '@/components/DepatureInfo'
import BreakDownInfo from '@/components/BreakDownInfo'
import WithDrawalInfo from '@/components/WithDrawalInfo'
import UploadCarState from '@/components/UploadCarState'
export default {
  name: 'RefundManageDialog',
  components: {
    ManageInfo,
    DepatureInfo,
    BreakDownInfo,
    WithDrawalInfo,
    UploadCarState
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    row: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      title: '',
      breakFolder: 'breakRules',
      form: {
        mileage: ''
      }
    }
  },
  methods: {
    handleCancel() {
      this.$emit('cancel-dialog')
      this.$refs.refundManageDialog.resetFields()
    },
    handleConfirm() {
      this.$refs.refundManageDialog.validate((valid) => {
        if (valid) {
          this.$emit('confirm-dialog', {
            id: this.row.id,
            violation: this.row.violation,
            refund: this.row.refund,
            break: this.row.break,
            breakDes: this.row.breakDes,
            gps: this.row.gps
          })
        } else {
          return false
        }
      })
    },
    handleUploadBreak(url) {
      this.row.break = url
    }
  }
}
</script>

<style scoped>
  .refund-manag-title {
    border-bottom: 1px solid #ddd;
    height: 30px;
    font-size: 16px;
    font-weight: bold;
  }
</style>
